<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
<title>Document</title>
<link rel="stylesheet" href="../assets/agile/css/ratchet/css/ratchet.min.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.component.css">
<link rel="stylesheet" href="../assets/agile/css/flat/flat.color.css">
<link rel="stylesheet" href="../assets/agile/css/flat/iconline.css">
<link rel="stylesheet" href="../assets/app/css/app.css" />
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery.js"></script>
<script type="text/javascript" src="../script/config.js"></script>
<script type="text/javascript" src="../script/local.js"></script>
<script type="text/javascript" src="../script/common.js"></script>
</head>
<body>

<!--通用顶部-->
<div id="ios-top-box">
    <div id="header" class="bar bar-nav">
    <div class="titlebar">
    <a href="javascript:appClose('wx',api);"><i class="iconfont iconline-arrow-left"></i></a>
    <h1 class="title">微信分享</h1>
    </div>
    </div>
</div>
<!--通用顶部结束-->

<section class="notBottom">
    <div class="scroller create_goods">
        
        <a href="javascript:;" style="margin:64px auto 10px auto;" class="common-btn" id="wxshare">微信分享</a>
        <a href="javascript:;" style="margin:10px auto;" class="common-btn" id="wxpay">微信支付</a>
        
    </div>
</section>

<script type="text/javascript" charset="utf-8">
apiready = function(){
	
	var wxshare = document.getElementById('wxshare');
	
	wxshare.onclick = function(){
		var wx = api.require('wx');
		wx.isInstalled(function(ret, err){
		    if(ret.installed){
		    	wx.shareText({
		    	    apiKey: 'wx2bb60a68a6aefbf8',
		    	    scene: 'timeline',
		    	    text: '我分享的文本'
		    	}, function(ret, err){
		    	    if(ret.status){
		    	        alert('分享成功');
		    	    }else{
		    	        alert(err.code);
		    	    }
		    	});
		    	
		    }else{
		        alert('当前设备未安装微信客户端');
		    }
		});
	};
	
	var wx_pay = document.getElementById('wxpay');
	wx_pay.onclick = function(){
		
		
		function getNowFormatDate() {
		    var date = new Date();
		    var seperator1 = "";
		    var seperator2 = "";
		    var month = date.getMonth() + 1;
		    var strDate = date.getDate();
		    if (month >= 1 && month <= 9) {
		        month = "0" + month;
		    }
		    if (strDate >= 0 && strDate <= 9) {
		        strDate = "0" + strDate;
		    }
		    var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
		             + date.getHours() + seperator2 + date.getMinutes()
		            + seperator2 + date.getSeconds();
		    return currentdate;
		}
			var weiXin = api.require('weiXin');
			weiXin.registerApp(
				    function(ret,err){
				        if (ret.status) {
				        	

				            var wxPay = api.require('wxPay');
				            wxPay.config({
				                 apiKey: config.wxpay.app_id,
				                 mchId: config.wxpay.mchid,
				                 partnerKey: config.wxpay.pay_key,
				                 notifyUrl: 'http://jxdb.test.com/wx_return_url.php'
				            }, function(ret, err){
				                 if(ret.status){
				                    var date = parseInt(new Date().getTime()/1000)+new Date().getTime();
				                    wxPay.pay({
				                         description: 'iPad mini 16G 白色',
				                         totalFee: '888',
				                         tradeNo: '121'+date,
				                         spbillCreateIP: '196.168.1.1',
				                         deviceInfo: 'nice172',
				                         detail: 'iPad mini 16G 白色',
				                         attach: '说明',
				                         feeType: 'CNY',
				                         timeStart: getNowFormatDate(),
				                         timeExpire: parseInt(getNowFormatDate())+60*10,
				                         goodsTag: 'WXG',
				                         productId: '1024',
				                    },function(ret, err){
				                         if(ret.status){
				                             alert(ret.result);
				                         }else{
				                             alert(err.code);
				                         }
				                    });
				                    
				                 }else{
				                     alert(err.code);
				                 }
				            });
				        	
				        } else{
				            api.alert({msg:err.msg});
				        }
				    }
				);
			
	};
	
}
</script>
</body>
</html>